package logic.obstacles
{

    import flash.display.*;
    import flash.geom.*;
    
	import events.SoundEvent;

    public class ElectricCharge extends GeneralObstacle
    {
    
        private var particleEm:ParticleEmmiter;
        private var shouldUpdate:Boolean = true;      
        private var pcLifetime = 120;
        private var delay = 120;
        private var config:Object;
        
        public function ElectricCharge(configuration:Object)
        {
            config = configuration;
            delay = configuration.delay;
            pcLifetime = config.sleep;
            
            particleEm = new ParticleEmmiter();
            particleEm.x = -10;
            particleEm.y = 0;
            particleEm.xVelocity = 0;
            particleEm.xSpread = 10;
            particleEm.yVelocity = -4;
            particleEm.ySpread = 4;
            particleEm.beginColor = 0x1EF2FF;
            particleEm.endColor = 0xFFFFFF;
            particleEm.maxParticles = 30
            particleEm.lifetime = 6;
            particleEm.minGen = 30;
            particleEm.maxGen = 50;

            addChild(particleEm); 

        } 
    
        public override function draw():void
        {
            
        }
        
        
        public override function update():void
        {     
            if(delay != 0)
            {
                delay--;
                return;
            }  
                 
            if (shouldUpdate)
            {
                shouldUpdate = false;                   
                particleEm.start();
                dispatchEvent(new SoundEvent(SoundEvent.PLAY_SOUND, {sound:"electric"}, true)); 	   
            }
            else 
            {
                pcLifetime--;
                if (pcLifetime==0) 
                {
                    pcLifetime = config.sleep ;
                    shouldUpdate = true;
                    
                }
                if(pcLifetime < config.sleep - 20)
                    particleEm.stop();
            }
        }
    
    }

}
